// components/custom-header/custom-header.js
Component({
    properties: {
        title: {
            type: String,
            value: '红旗'
        },
        showBack: {
            type: Boolean,
            value: true
        }
    },
    data: {
        statusBarHeight: 20, // 状态栏高度
        navBarHeight: 44, // 导航栏总高度
        menuLeft: 0, // 胶囊按钮左侧距离
        menuWidth: 87,// 胶囊按钮占位宽度（用于右侧留白）
        menuRightPadding:0,
    },
    lifetimes: {
        attached() {
            const systemInfo = wx.getWindowInfo()
            const menuButtonInfo = wx.getMenuButtonBoundingClientRect()

            // 精确计算导航栏高度
            const navBarHeight = (menuButtonInfo.top - systemInfo.statusBarHeight) * 2 + menuButtonInfo.height

            this.setData({
                statusBarHeight: systemInfo.statusBarHeight,
                navBarHeight: navBarHeight,
                menuLeft: menuButtonInfo.left,
                menuWidth: menuButtonInfo.width, // 增加10px安全边距
                menuRightPadding:systemInfo.screenWidth - menuButtonInfo.right,
            })

            console.log(systemInfo)
            console.log(menuButtonInfo)
        }
    },
    methods: {
        handleBack() {
            console.log("back")
            this.triggerEvent('back')
            wx.navigateBack({
                success(res) {},
                fail(res) {
                    // wx.switchTab({
                    //     url: '/pages/index/index',
                    // })

                    wx.reLaunch({
                        url: '/pages/index/index',
                    })
                }
            });
        }
    }
})